<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>品优购，欢迎登录</title>

    <link rel="stylesheet" type="text/css" href="../css/all.css" />
    <link rel="stylesheet" type="text/css" href="../css/pages-login.css" />
	<link rel="shortcut icon" href="http://bj960928.3vzhuji.net/favicon.ico" type="image/x-icon">
	<script src="../js/jquery.min.js"></script>
</head>

<body>
	<div class="login-box">
		<!--head-->
		<div class="py-container logoArea">
			<a href="" class="logo"></a>
		</div>
		<!--loginArea-->
		<div class="loginArea">
			<div class="py-container login">
				<div class="loginform">
					<ul class="sui-nav nav-tabs tab-wraped">
						<li>
							<a href="#index" data-toggle="tab">
								<h3>扫描登录</h3>
							</a>
						</li>
						<li class="active">
							<a href="#profile" data-toggle="tab">
								<h3>账户登录</h3>
							</a>
						</li>
					</ul>
					<div class="tab-content tab-wraped">
						<div id="index" class="tab-pane">
							<p>二维码登录，暂为官网二维码</p>
							<img src="../img/wx_cz.jpg" />
						</div>
						<div id="profile" class="tab-pane  active">
							<form class="sui-form">
								<div class="input-prepend"><span class="add-on loginname"></span>
									<input id="prependedInput" autocomplete="off" type="text" placeholder="邮箱/用户名/手机号" class="span2 input-xfat">
								</div>
								<div class="input-prepend"><span class="add-on loginpwd"></span>
									<input id="prependedInput" type="password" placeholder="请输入密码" class="span2 input-xfat">
								</div>
								<div class="setting">
									<label class="checkbox inline">
          <input name="m1" type="checkbox" value="2" checked=""> 
          自动登录
        </label>
									<span class="forget">忘记密码？</span>
								</div>
								<div class="logined">
									<a class="sui-btn btn-block btn-xlarge btn-danger" href="home.html" target="_blank">登&nbsp;&nbsp;录</a>
								</div>
							</form>
							<div class="otherlogin">
								<div class="types">
									<ul>
										<li><img src="../img/qq.png" width="35px" height="35px" /></li>
										<li><img src="../img/sina.png" /></li>
										<li><img src="../img/ali.png" /></li>
										<li><img src="../img/weixin.png" /></li>
									</ul>
								</div>
								<span class="register"><a href="register.html" target="_blank">立即注册</a></span>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!--foot-->
		<div class="py-container copyright">
			<ul>
				<li>关于我们</li>
				<li>联系我们</li>
				<li>联系客服</li>
				<li>商家入驻</li>
				<li>营销中心</li>
				<li>手机品优购</li>
				<li>销售联盟</li>
				<li>品优购社区</li>
			</ul>
			<div class="address">地址：北京市昌平区建材城西路金燕龙办公楼一层 邮编：100096 电话：400-618-4000 传真：010-82935100</div>
			<div class="beian">京ICP备08001421号京公网安备110108007702
			</div>
		</div>
	</div>
</body>
<script>
	function setCookie(cname, cvalue, exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays*24*60*60*1000));
        var expires = "expires="+ d.toUTCString();
        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
    } 
    function getCookie(cname) {
        var name = cname + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');
        for(var i = 0; i <ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }
	$(document).ready(function(){
		//先判断是否登录
		if(getCookie("login")!=''){
			if(confirm("您已经登陆，是否注销？")){
				setCookie("login",getCookie("login"),-1);
			}else{
				location.href="index.html";
			}
		}else if(window.sessionStorage.getItem("login")!=null){
			if(confirm("您已经登陆，是否注销？")){
				window.sessionStorage.removeItem("login");
			}else{
				location.href="index.html";
			}
		}
		$("[data-toggle=tab]").click(function(){
			$(this).parent().attr("class","active");
			$(this).parent().siblings().attr("class","");
			$(".tab-pane").hide();
			$(this.getAttribute("href")).show();
		})
		$(".sui-btn").click(function(){
			$(this).html("验证中");
			let phone = $("input[type=text]").val();
			let pwd = $("input[type=password]").val();
			let data = check(phone,pwd);
			//获取自动登录
			let checkbok = $("[name=m1]").prop("checked");
			if(data==undefined){
				alert("登陆失败");
				$(this).html("登&nbsp;&nbsp;录");
			}else{
				$(this).html("验证成功");
				$(this).attr("disabled","true");
				if(checkbok){
					//存入cookie，两天销毁
					setCookie("login",data.phone,2);
				}else{
					window.sessionStorage.setItem("login",data.phone);
				}
				location.href="index.html";
			}
			return false;	
		});
		//登陆验证
		function check(phone,pwd){
			var flag = undefined;
			$.ajax({
				url:`http://localhost:3301/user?phone=${phone}&password=${pwd}`,
				async:false,
				type:"get",
				success:function(data){
					flag = data[0];
				}
			})
			return flag;
		}	
	})
</script>
</html>